package cn.tedu.spring;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Date;
import java.util.Random;

public class SpringRun {
    public static void main(String[] args) {
        //1.加载Spring
        AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(SpringBeanFactory.class);
        //2.从Spring中获取对象
        Random random = (Random) ac.getBean("random");
        Random random2 = (Random) ac.getBean(Random.class);
        Random random1 = ac.getBean("random",Random.class);//推荐这种
        Date date = ac.getBean("date",Date.class);//推荐这种
        //3.测试使用对象,以便于观察是否获取到了有效的对象
        System.out.println("random>"+random);
        System.out.println("random.nextInt()>"+random.nextInt());
        System.out.println(random1.nextBoolean());
        System.out.println(date);
        //4.关闭
        ac.close();
    }
}
